﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using IR.WPF.Interfaces;

namespace IR.WPF.ViewModels.LandingViewModels
{
    public class ViewModelBase : IHandleCleanup, INotifyPropertyChanged
    {
        private string _windowTitle = "Idea Repository";
        public Window BoundWindow { get; set; }

        /// <summary>
        /// Gets or sets the Window Title for this ViewModel (if the window is paying attention to it)
        /// </summary>
        public string WindowTitle
        {
            get { return _windowTitle; }
            set
            {
                if (_windowTitle == value)
                    return;
                _windowTitle = value;
                NotifyPropertyChanged("WindowTitle");
            }
        }

        /// <summary>
        /// Optionally compares the other view model to this instance in order to determine if the new model is distinct from this one when 
        /// the view model is used in a window type that only allows a single instance of a given data set
        /// </summary>
        /// <param name="compareToModel">Reference to the view model to be compared</param>
        /// <returns>True if the new view model is allowed to create a new view</returns>
        public virtual bool AllowNewView(ViewModelBase compareToModel)
        {
            return true;
        }

        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// Raises the PropertyChanged event.
        /// </summary>
        /// <param name="propertyName">Name of the Property that was changed</param>
        /// <param name="passThroughSender">Optional reference to another sender if this instance is not intended to be the sender</param>
        public virtual void NotifyPropertyChanged(string propertyName, object passThroughSender = null)
        {
            if (PropertyChanged != null)
                PropertyChanged(passThroughSender ?? this, new PropertyChangedEventArgs(propertyName));
        }

        public virtual void DoCleanup()
        {
        }
    }
}
